package com.easy.service.impl;

import com.easy.annotation.LogMethod;
import com.easy.bean.Department;
import com.easy.mapper.DepartmentMapper;
import com.easy.service.DepartmentService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DepartmentServiceImpl implements DepartmentService {

    @Autowired
    private DepartmentMapper departmentMapper;

    @Override
    public Object page(Page page, Department department) {
        // 查询总条数
        int count = departmentMapper.count(department);
        page.setCount(count);
        // 查询分页数据
        List<Department> list = departmentMapper.page(department, page);
        page.setData(list);
        return page;
    }

    @Override
    @LogMethod(serviceName = "新增科室信息")
    public Department add(Department department) {
        departmentMapper.add(department);
        // 新增后返回完整数据
        return departmentMapper.one(department.getId());
    }


    @Override
    @LogMethod(serviceName = "删除科室信息")
    public int del(Integer id) {
        return departmentMapper.del(id);
    }

    @Override
    @LogMethod(serviceName = "修改科室信息")
    public Department edit(Department department) {
        departmentMapper.edit(department);
        // 编辑后返回更新的数据
        return departmentMapper.one(department.getId());
    }

    @Override
    public List<Department> all(Department department) {
        return departmentMapper.all(department);
    }

    @Override
    public Department one(Integer id) {
        return departmentMapper.one(id);
    }
}
